<template>
  <base-layout
    :dialog-close-confirm="false"
    :dialog-visible="dialogVisible"
    dialog-title="出库详情"
    @dialog-close="dialogClose"
    dialogWidth="80%"
  >
    <template #searchPanel>
      <search-panel
        ref="searchPanel"
        v-slot="{ form }"
        addTitle="新增出库"
        @search="search"
        :selectPer="authConfig.query"
        @insert="addHandle"
        :addPer="authConfig.add"
        showExportButton
        showAddButton
        :excelPer="authConfig.export"
        @export="exportHandle"
      >
        <job-shop v-model="form.storeId" placeholder="所属门店" />
        <el-select v-model="form.storageType" clearable placeholder="出库类型">
          <el-option
            v-for="item in dict['精品出库类型']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
        <el-input
          v-model="form.likeName"
          clearable
          placeholder="出库编号"
          style="width: 200px"
        />
      </search-panel>
    </template>

    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        @row-dblclick="detailHandle"
        :width="160"
      >
        <template #action="{row}">
          <i
            class="el-icon-edit pointer"
            title="编辑"
            v-permission="authConfig.edit"
            @click="editHandle(row, '编辑')"
          ></i>
          <i
            class="el-icon-delete pointer ml-20"
            title="删除"
            v-permission="authConfig.del"
            @click="handleDataDelete(row)"
          ></i>
        </template>
      </data-table>
      <!--工具条-->
    </template>
    <template #dialog>
      <put-out-detail v-if="detailData" :detail-data="detailData" />
    </template>
  </base-layout>
</template>

<script>
import baseMixin from '@/mixins/base'
import { getDict } from '@/utils/index'
import PutOutDetail from './components/putOutDetail'
import { pageList, deleteById } from '@/api/pre-sale/boutiqueStock/putOut'
import { exportExcel } from '@/utils'

// 采购申请页面
export default {
  components: {
    PutOutDetail
  },
  mixins: [
    baseMixin({
      findData: pageList,
      dataName: ['content', 'totalRecords'],
      deleteData: deleteById,
      idName: 'id',
      format(res) {
        return res.map(data => {
          return data
        })
      }
    })
  ],
  data() {
    this.authConfig = {
      query: 'brandOutStorage:page',
      export: '111',
      add: 'brandOutStorage:save',
      edit: 'brandOutStorage:update',
      del: 'brandOutStorage:del'
    }
    return {
      dialogVisible: false,
      tableColumnAttributes: [
        { name: '所属门店', value: 'storeName', type: 'text' },
        { name: '出库编号', value: 'outStorageCode', type: 'text' },
        { name: '出库类型', value: 'outStorageType', type: 'dict', dict: '精品出库类型' },
        { name: '出库仓库', value: 'storageName', type: 'text' },
        { name: '仓库编号', value: 'storageCode', type: 'text' },
        { name: '出库负责人', value: 'userName', type: 'text' },
        { name: '负责人联系方式', value: 'phone', type: 'text' },
        { name: '单据日期', value: 'receiptsTime', type: 'text' },
        { name: '出库精品数量', value: 'partsNum', type: 'text' },
        { name: '出库总金额', value: 'amount', type: 'text' },
        { name: '出库备注', value: 'remark', type: 'text' },
        { name: '出库状态', value: 'status', type: 'text' },
        { name: '录入时间', value: 'createTime', type: 'text' }
      ],
      detailData: null
    }
  },
  methods: {
    addHandle() {
      this.$router.push({ name: 'putOutAdd', params: { id: 0, outStorageType: '销售出库', sourceCode: 0 }})
    },
    exportHandle() {
      exportExcel("BrandOut", "精品出库", {}, this.pageSize, this.currentPage);
    },
    editHandle(row) {
      this.$router.push({ name: 'putOutEdit', params: { id: row.id, outStorageType: row.outStorageType || '销售出库', sourceCode: row.workOrderCode || 0 }})
    },
    detailHandle(row) {
      this.detailData = row
      this.dialogVisible = true
    },
    search(form) {
      this.searchOptions = {
        storeId: form.storeId,
        likeName: form.likeName,
        storageType: form.storageType
      }
      this.currentPage = 1
      this.setTableData()
    }
  },
  created() {
    this.dict = getDict(['精品出库类型'])
  },
  mounted() {}
}
</script>

<style lang="scss" scoped></style>
